/*
 * @lc app=leetcode.cn id=914 lang=javascript
 *
 * [914] 卡牌分组
 */

// @lc code=start
var gcd = (a, b) => {
  if (b == 0) return a;
  return gcd(b, a % b);
}
/**
 * @param {number[]} deck
 * @return {boolean}
 */
var hasGroupsSizeX = function (deck) {
  const map = {};
  deck.forEach(num => {
    map[num] = map[num] ? map[num] + 1 : 1;
  })
  return Object
    .entries(map)
    .map(([_, v]) => v)
    .reduce((pre, cur) => gcd(pre, cur)) !== 1;
};
// @lc code=end

